package com.zoc.service.prd.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zoc.common.SuperUtils;
import com.zoc.common.service.impl.SuperServiceImpl;
import com.zoc.entity.prd.Member;
import com.zoc.entity.prd.PayDetail;
import com.zoc.entity.security.User;
import com.zoc.repository.prd.MemberDao;
import com.zoc.service.prd.MemberService;
import com.zoc.service.security.UserService;

@Service
public class MemberServiceImpl extends SuperServiceImpl<Member, Long> implements MemberService {

	@Autowired
	MemberDao memberDao;
	
	@Autowired
	UserService userService;

	@Override
	public void initStatements() {
		this.setStatement(MemberDao.class.getName());
	}

	@Override
	public Member fetch(String member_id) {
		return memberDao.fetch(member_id);
	}

	@Override
	public List<PayDetail> listPayDetail(PayDetail payDetail) {
		// TODO Auto-generated method stub
		return memberDao.listPayDetail(payDetail);
	}

	@Override
	public void updatePayDetail(PayDetail payDetail) {
		// TODO Auto-generated method stub
		memberDao.updatePayDetail(payDetail);
	}

	@Override
	public void insertPayDetail(PayDetail payDetail) {
		// TODO Auto-generated method stub
		memberDao.insertPayDetail(payDetail);
	}

	@Override
	public void updateLevel(Member member) {
		memberDao.updateLevel(member);
	}
	
	@Override
	@Transactional
	public void batchSave(List<Member> lists){
		for(Member m : lists){
			if(SuperUtils.isNullOrEmpty(m.getMobile())){
				continue;
			}
			m.setMobile(m.getMobile().replaceAll("-", ""));
			m.setMember_id(m.getMobile());
			m.setLevel("0");
			memberDao.insert(m);
			User user = new User();
			user.setUsername(m.getMember_id());
			user.setPassword("123456");
			user.setUser_type("M");
			userService.add(user);
		}
	}
}
